package com.example.evaluate.model;

import com.alibaba.fastjson.JSON;
import lombok.*;

import java.text.DecimalFormat;

@Setter
@Getter
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
public class TeacherCourse {
    private int teacherCourseId;
    private String courseName;
    private int trueTeacherId;
    private int numberOfStudent;
    private int numberOfEvaluateStudent;
    private String evaluate;
    private String url;

    public TeacherCourse(String courseName, int trueTeacherId) {
        this.courseName = courseName;
        this.trueTeacherId = trueTeacherId;
        this.url = "/getQuestionAdviceByTeacherCourse?courseName="+courseName;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public void setEvaluate(int numberOfEvaluateStudent,int numberOfStudent){
        if (numberOfStudent==0||numberOfEvaluateStudent==0){
            this.evaluate = "0%";
        }else {
            double temp = ((double)numberOfEvaluateStudent/(double) numberOfStudent) * 100;
            String res = String.format("%.2f",temp) + "%";
            this.evaluate = res;
        }
    }
}
